package com.liwenfeng.linkedlist;

import com.liwenfeng.domain.UserN;

import java.util.*;

public class MyLinkedListTest {
    public static void main(String[] args) {
//        new MyLinkedListTest().intTest();
        new MyLinkedListTest().userNTest();
    }

    public void intTest(){
        MyLinkedList<Integer> list1 = new MyLinkedList<>();
        list1.add(2);
        list1.add(4);
        list1.add(1);

        MyLinkedList.Node<Integer> head1 = list1.head;

//        list1.forEach(System.out::println);
        MyLinkedList<Integer> list2 = new MyLinkedList<>();
        list2.add(4);
        list2.add(1);
        list2.add(3);

        MyLinkedList.Node<Integer> head2 = list2.head;

        //1.在MyLinkedList类中开发sort方法，对两个表分别排序，并遍历输出；
        System.out.print("list1升序-->\t\t");
        list1.sort(Integer::compareTo);
        list1.forEach(item-> System.out.print(item+" "));
        System.out.println();
        System.out.print("list2升序-->\t\t");
        list2.sort(Comparator.comparing(e -> e));
        list2.forEach(item-> System.out.print(item+" "));
        System.out.println();

        //2.再开发mergeSort方法，支持两个升序的链表合并成一个新表，新表仍然是升序，遍历输出；
        System.out.print("合并后-------->\t");
//        list1.mergeSort(list2, false);
        list1.merge(list2);
        list1.forEach(item-> System.out.print(item+" "));
        System.out.println();
        System.out.print("反转后------>\t");
        list1.reversed();
        list1.forEach(item-> System.out.print(item+" "));
        System.out.println();
        System.out.print("冒泡排序---->\t");
        list1.sort(e->e, MyLinkedList.Sortord.INSERT);
        list1.forEach(item-> System.out.print(item+" "));
        System.out.println();
        System.out.print("反转-------->\t");
        list1.reversed();
        list1.forEach(item-> System.out.print(item+" "));
        System.out.println("\n"+list1.size());

//        System.out.println("删除后结果-->");
//        list1.remove(2);
//        list1.forEach(System.out::println);
//        System.out.println("长度："+list1.size());
    }

    public void userNTest(){
        MyLinkedList<UserN> list1 = new MyLinkedList<>();
        list1.add(new UserN("zhangsan",19,160.0));
        list1.add(new UserN("李四",19,178.0));
        list1.add(new UserN("王五",19,160.0));

//        list1.forEach(System.out::println);
        MyLinkedList<UserN> list2 = new MyLinkedList<>();
        list2.add(new UserN("张十五",18,176.0));
        list2.add(new UserN("令狐冲",36,160.0));
        list2.add(new UserN("张三丰",22,190.0));


        //1.在MyLinkedList类中开发sort方法，对两个表分别排序，并遍历输出；
        System.out.println("list1升序-->");
        list1.sort(((o1, o2) -> o2.getHeight().compareTo(o1.getHeight())));
        list1.forEach(System.out::println);

        System.out.println("list2升序-->");
        list2.sort(Comparator.comparing(UserN::getHeight));
        list2.forEach(System.out::println);

        //2.再开发mergeSort方法，支持两个升序的链表合并成一个新表，新表仍然是升序，遍历输出；
        System.out.println("合并后-------->");
//        list1.mergeSort(list2, false);
        list1.merge(list2);
        list1.forEach(System.out::println);
        System.out.println("反转后------>");
        list1.reversed();
        list1.forEach(System.out::println);

        System.out.println("冒泡、插入、快速三种方法排序---->");
//        list1.sort(UserN::getHeight, MyLinkedList.Sortord.BUBBLE);
        list1.sort((o1, o2) -> {
            int result = o1.getHeight().compareTo(o2.getHeight());
            if (result==0){
                result = o1.getAge().compareTo(o2.getAge());
                if (result==0){
                    result = o1.getName().compareTo(o2.getName());
                }
            }
            return result;
        });
        list1.forEach(System.out::println);

        System.out.println("反转-------->");
        list1.reversed();
        list1.forEach(System.out::println);
        System.out.println("\n"+list1.size());

        MyLinkedList<UserN>.Itr iterator = list1.iterator();

        System.out.println(iterator.hasNext());
        iterator.add(new UserN("gggggg",22,190.0));
        while (iterator.hasNext()){
            UserN next = iterator.next();
            if (Objects.equals(next.getName(), "张三丰")) System.out.println("---------"+iterator.currentIndex());
            System.out.println(next);
        }
        System.out.println("===============");
        list1.forEach(System.out::println);

//        System.out.println(list1.get(4));
        MyLinkedList<UserN> userNMyLinkedList = new MyLinkedList<>();
        userNMyLinkedList.iterator().set(new UserN("zhangsan",19,160.0));
        userNMyLinkedList.forEach(System.out::println);

        Collection<String> list = Arrays.asList("1","2","3","4","5","6","7","8","9","10");
        Iterator<String> iterator1 = list.iterator();

    }
}
